package com.ruoyi.web.controller.edh;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.edh.domain.EdhProfit;
import com.ruoyi.edh.domain.vo.EdhProfitVo;
import com.ruoyi.edh.service.IEdhProfitService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 易订货-收益Controller
 *
 * @author xxx
 * @date 2020-09-02
 */
@RestController
@RequestMapping("/edh/profit")
@Api(description = "易订货-收益")
public class EdhProfitController extends BaseController {
    @Autowired
    private IEdhProfitService edhProfitService;

    /**
     * 查询易订货-收益列表
     */
    @PreAuthorize("@ss.hasPermi('system:profit:list')")
    @GetMapping("/list")
    @ApiOperation("易订货-收益列表")
    public TableDataInfo list(EdhProfitVo edhProfit) {
        startPage();
        List<EdhProfitVo> list = edhProfitService.selectEdhProfitList(edhProfit);
        return getDataTable(list);
    }

    /**
     * 导出易订货-收益列表
     */
    @PreAuthorize("@ss.hasPermi('system:profit:export')")
    @Log(title = "易订货-收益", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    @ApiOperation("导出易订货-收益列表")
    public AjaxResult export(EdhProfitVo edhProfit) {
        List<EdhProfitVo> list = edhProfitService.selectEdhProfitList(edhProfit);
        ExcelUtil<EdhProfitVo> util = new ExcelUtil<EdhProfitVo>(EdhProfitVo.class);
        return util.exportExcel(list, "profit");
    }

    /**
     * 获取易订货-收益详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:profit:query')")
    @GetMapping
    @ApiOperation("获取易订货-收益详细信息")
    public AjaxResult getInfo(Long id) {
        return AjaxResult.success(edhProfitService.selectEdhProfitById(id));
    }

    /**
     *
     */
    @GetMapping("/getmineprofit")
    @ApiOperation("获取本人的收益信息")
    public AjaxResult getMineProfit() {
        return AjaxResult.success(edhProfitService.getMineProfit());
    }

    /**
     * 新增易订货-收益
     */
    @PreAuthorize("@ss.hasPermi('system:profit:add')")
    @Log(title = "易订货-收益", businessType = BusinessType.INSERT)
    @PostMapping
    @ApiOperation("新增易订货-收益")
    public AjaxResult add(@RequestBody EdhProfit edhProfit) {
        return toAjax(edhProfitService.insertEdhProfit(edhProfit));
    }

    /**
     * 修改易订货-收益
     */
    @PreAuthorize("@ss.hasPermi('system:profit:edit')")
    @Log(title = "易订货-收益", businessType = BusinessType.UPDATE)
    @PutMapping
    @ApiOperation("修改易订货-收益")
    public AjaxResult edit(@RequestBody EdhProfit edhProfit) {
        return toAjax(edhProfitService.updateEdhProfit(edhProfit));
    }

    /**
     * 删除易订货-收益
     */
    @PreAuthorize("@ss.hasPermi('system:profit:remove')")
    @Log(title = "易订货-收益", businessType = BusinessType.DELETE)
    @DeleteMapping
    @ApiOperation("删除易订货-收益")
    public AjaxResult remove(Long[] ids) {
        return toAjax(edhProfitService.deleteEdhProfitByIds(ids));
    }
}
